package zgame.main;

import java.io.IOException;

import org.apache.log4j.Logger;

import zgame.bean.Port;
import zgame.socket.client.ClientConnection;

public class Main {
  private static final Logger log = Logger.getLogger(Main.class);
  
  public static void main(String[] args) {
    try {
      Initialize.init();
      Initialize.initForCache();
      
      // Start job to reload config sequence
      Global.reloadConfigJob.setDelay(Global.RELOAD_CONFIG_INTERVAL).start();
      
    } catch (IOException e) {
      log.error("Server can't start.Please check your config file");
      return;
    }
    
    Port serviceControlPort = Global.defaultServiceInfo.getPort(Constants.SERVICE_CONTROL_PORT_NAME);

    // Connect to DefaultService to regist GameService
    log.info("Connect to DEFAULT SERVICE at " + Global.defaultServiceInfo.getUrl() + ":" + serviceControlPort.getValue());
    Global.client = new ClientConnection(Global.defaultServiceInfo.getUrl(), serviceControlPort.getValue(), Global.socketClientHandle);
  }
}
